package com.disease.api.service.model;

import lombok.Data;

@Data
public class ResponseResult<T> {

    private Integer code;

    private String message;

    private T data;

    public boolean isSuccess() {
        if(null==code){
            return false;
        }
        return code == 200 || code == 0;
    }

    public static <T> ResponseResult<T> success(T data) {
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setCode(200);
        responseResult.setMessage("success");
        responseResult.setData(data);
        return responseResult;
    }

    public static <T> ResponseResult<T> success(String message,T data) {
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setCode(200);
        responseResult.setMessage(message);
        responseResult.setData(data);
        return responseResult;
    }

    public static <T> ResponseResult<T> success() {
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setCode(200);
        responseResult.setMessage("success");
        return responseResult;
    }

    public static <T> ResponseResult<T> fail(String message) {
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setCode(400);
        responseResult.setMessage(message);
        return responseResult;
    }

    public static <T> ResponseResult<T> invalidToken() {
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setCode(401);
        responseResult.setMessage("Invalid or missing token");
        return responseResult;
    }

}
